﻿
using Light.Framework.Component;
using Light.Framework.Contract;
using Light.Weixin.Contract;
using Light.Weixin.Model;
using Light.Framework.Model;
using Light.Framework;

namespace Light.Weixin.Component
{
    public class WxAnswerComponent : BaseComponent<WxAnswer>, IWxAnswerComponent
    {
        public string GetAnswer(WxMsg msg)
        {
            using (new GuestUser())
            {
                WxAnswerComponent comp = new WxAnswerComponent();
                SearchArgs args = new SearchArgs();
                args.Add(SearchLogic.And, "WxApp.OriginalID", msg.ToUserName);
                args.Add(SearchLogic.And, "Keywords", msg.Content.ToLower());

                WxAnswer answer = comp.Get(args);
                if (answer != null)
                {
                    return answer.Content;
                }
                else
                {
                    return null;
                }
            }
        }

        public string GetAnswerDefault(string originalId)
        {
            using (new GuestUser())
            {
                WxAnswerComponent comp = new WxAnswerComponent();
                SearchArgs args = new SearchArgs();
                args.Add(SearchLogic.And, "WxApp.OriginalID", originalId);
                args.Add(SearchLogic.And, "Keywords", "unknow");

                WxAnswer answer = comp.Get(args);
                if (answer != null)
                {
                    return answer.Content;
                }
                else
                {
                    return null;
                }
            }
        }
    }
}
